from __future__ import absolute_import
from __future__ import print_function

import os
import json
from keras.optimizers import Adam, SGD

from meta import TrainingMetadata
from experiment import TRAINING_JSON, META_DIR


def get_training_metadata(cont=False):
    training_metadata = TrainingMetadata()
    training_metadata.optimizer = SGD(momentum=0.9, decay=0.9, lr=0.01)
    training_metadata.loss = 'rmse'
    training_metadata.batch_size = 48
    training_metadata.nb_epoch = 1
    training_metadata.nb_iter = 200
    training_metadata.files_per_batch = 0
    training_metadata.shuffle = True

    # read performance log from file, if continue experiment
    if cont:
        dir = os.path.dirname(os.path.abspath(__file__))
        path = dir + '/' + META_DIR + '/' + TRAINING_JSON
        if os.path.isfile(path):
            f = open(path, 'rb')
            metadata_json = json.load(f)
            training_metadata.performance = metadata_json['performance']
    return training_metadata
